home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #3 / Amiga Plus CD - 1997 - No. 03.iso / pd / demo-versionen / maxoncpp4-demo / demo / supercode / message.c < prev    next >
C/C++ Source or Header  |  1996-12-31  |  9KB  |  426 lines

  1. //-------------------------------------
  2. //
  3. // SuperCode (c) 1996 by T.Kühn 
  4. //
  5. // Programmiersprache:    ANSI-C
  6. // Projektstart:            27.12.94
  7. //
  8. // Modul:                Messages
  9. //                        Ports
  10. //
  11. //-------------------------------------
  12.  
  13.  
  14. /*-------------------------------------
  15. VOID Msg_GetWin();
  16. VOID Msg_GetWb();
  17. VOID Msg_GetCx();
  18. VOID Wait_All();
  19. VOID Draw_Border(struct WinBlk *Blk,struct GadInfo *Info);
  20. VOID Draw_NextBorder(struct GadInfo *Info);
  21. -------------------------------------*/
  22.  
  23.  
  24. #include <workbench/startup.h>
  25.  
  26. #include <pragma/gadtools_lib.h>
  27. #include <pragma/graphics_lib.h>
  28. #include <pragma/exec_lib.h>
  29. #include <pragma/dos_lib.h>
  30. #include <pragma/intuition_lib.h>
  31. #include <pragma/keymap_lib.h>
  32. #include <pragma/wb_lib.h>
  33. #include <workbench/workbench.h>
  34.  
  35. #include <intuition/gadgetclass.h>
  36.  
  37. #include <pragma/commodities_lib.h>
  38. #include <libraries/commodities.h>
  39.  
  40. #include <Struct.h>
  41.  
  42. //-------------------------------------
  43. // Vars
  44. //-------------------------------------
  45.  
  46.  
  47. struct MsgPort            *Port_Win,*Port_Wb,*Port_Cx;
  48.  
  49. CxObj *Broker;
  50. /*
  51. struct NewBroker NewB=
  52. {
  53.     5,"Name","Title 09/1994",
  54.     "Info",
  55.     NBU_UNIQUE|NBU_NOTIFY,
  56.     COF_SHOW_HIDE,
  57.     0,0,0
  58. };
  59. */
  60.  
  61. /*
  62. //-------------------------------------
  63. VOID Command_CmpID(struct Gadget *gad,struct WinMsg *msg)
  64. {
  65.     struct GadInfo *info=gad->UserData;
  66.  
  67.     if (msg)
  68.     {
  69.         msg->Info=info;
  70. //        if      (msg->Class==IDCMP_GADGETDOWN)              msg->Blk->DownID=info;
  71. //        else if (msg->Class==IDCMP_MOUSEMOVE && !info) msg->Info=info=msg->Blk->DownID;
  72. //        else if (msg->Class==IDCMP_GADGETUP)                msg->Blk->DownID=0;
  73.     }
  74.     if (info)
  75.     {
  76.         switch (info->kind)
  77.         {
  78.             case BUTTON_CALC:
  79.                 break;
  80.         }
  81.         if (msg->Class==IDCMP_GADGETUP && info->func) (*info->func)(msg);
  82.     }
  83. }
  84. //-------------------------------------
  85. //-------------------------------------
  86. VOID Command_Key(struct WinMsg *Msg)
  87. {
  88.     struct WinBlk *Blk=Msg->Blk;
  89.     struct Window *Win=Msg->Win;
  90.     struct GadInfo *Info;
  91.     struct Gadget *Gad=0;
  92.     struct InputEvent Input;
  93.     UBYTE Str[5];
  94.     UWORD Raw,Asc,Qual;
  95. //    VOID (*Func)();
  96.     WORD c;
  97.     BOOL Up=FALSE;
  98.  
  99.     if (Blk && Win )
  100.     {
  101.         if (Msg->Code & 0x80) Up=TRUE;
  102.         Raw=Msg->Code & 0x7F;
  103.         Qual=Msg->Qualifier;
  104.         if (Raw<0x60 || Raw>0x67)
  105.         {
  106.             if (!Up)
  107.             {
  108.                 if (!(Qual&IEQUALIFIER_REPEAT))
  109.                 {
  110.                     if(Raw==0x45 && (Qual&ALT) )            // Esc
  111.                     {
  112.                         Window_Close(Blk);
  113.                     }
  114.                     else if(Raw==0x42 && (Qual&ALT) )
  115.                     {
  116.                         c=0;
  117.                         if (Qual&SHFT)
  118.                         {
  119.                             Blk=(APTR)Blk->Node.ln_Pred;
  120.                             while (!Blk->WinPtr && c<=1)
  121.                             {
  122.                                 Blk=(APTR)Blk->Node.ln_Pred;
  123.                                 if ((APTR)Blk->Node.ln_Pred==(APTR)&Blk_Head) {Blk=(APTR)Blk_Head.lh_TailPred;c++}
  124.                             }
  125.                         }
  126.                         else
  127.                         {
  128.                             Blk=(APTR)Blk->Node.ln_Succ;
  129.                             while (!Blk->WinPtr && c<=1)
  130.                             {
  131.                                 Blk=(APTR)Blk->Node.ln_Succ;
  132.                                 if (!Blk->Node.ln_Succ) {Blk=(APTR)Blk_Head.lh_Head;c++}
  133.                             }
  134.                         }
  135.                         if (Blk->WinPtr)
  136.                         {
  137.                             ActivateWindow(Blk->WinPtr);
  138.                             WindowToFront(Blk->WinPtr);
  139.                         }
  140.                     }
  141.                     else if(Raw==0x42)            // Tab
  142.                     {
  143.                         Info=Blk->LastGadInfo;
  144.                         do
  145.                         {
  146.                             if (Qual&SHFT)
  147.                             {
  148.                                 if (Info && (!LFrst(Info)) ) Info=LPrev(Info);
  149.                                 else if (!Empty(&Blk->GadInfo)) Info=(struct GadInfo*)Blk->GadInfo.lh_TailPred;
  150.                             }
  151.                             else
  152.                             {
  153.                                 if (Info && (!LLast(Info)) ) Info=LNext(Info);
  154.                                 else if (!Empty(&Blk->GadInfo)) Info=(struct GadInfo*)Blk->GadInfo.lh_Head;
  155.                             }
  156. //                        }while(Info && ((Info->Kind==TEXT_KIND)||(Info->Kind==BORDER_KIND)) && (Info!=Blk->LastGadInfo));
  157.                         Draw_NextBorder(Info);
  158.                     }
  159.                     else
  160.                     {
  161.                         Str[0]=0;
  162.                         Input.ie_NextEvent=0;
  163.                         Input.ie_Class=IECLASS_RAWKEY;
  164.                         Input.ie_SubClass=0;
  165.                         Input.ie_Code=Raw;
  166.                         Input.ie_Qualifier=Qual&~SHFT;
  167.                         MapRawKey(&Input,Str,4,0);
  168.                         Asc=Str[0];
  169. //printf("Raw:%X\n",Raw);
  170.                         if (Raw==0x40 || Raw==0x43 || Raw==0x44 || Raw==0x4c || Raw==0x4d || Raw==0x4e || Raw==0x4f )
  171.                         {
  172.                             Gadget_Action(Blk,Raw,Qual);
  173.                         }
  174.                         else
  175.                         {
  176.                             Info=(struct GadInfo*)Blk->GadInfo.lh_Head;
  177.                             while(LNext(Info))
  178.                             {
  179.                                 if (Info->Key==Asc)
  180.                                 {
  181.                                     Draw_NextBorder(Info);
  182.                                     break;
  183.                                 }
  184.                                 Info=LNext(Info);
  185.                             }
  186.                         }
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.     }
  192. }
  193. //-------------------------------------
  194. */
  195.  
  196. //-------------------------------------
  197. VOID Wait_All()
  198. {
  199.     ULONG Mask=0;
  200.  
  201.     if (Port_Cx)  Mask|=1<<Port_Cx ->mp_SigBit;
  202.     if (Port_Win) Mask|=1<<Port_Win->mp_SigBit;
  203.     if (Port_Wb)  Mask|=1<<Port_Wb ->mp_SigBit;
  204.     if (Mask) Wait(Mask);
  205. }
  206. //-------------------------------------
  207. ULONG wait_mask(ULONG mask)
  208. {
  209.     if (mask) mask=Wait(mask);
  210.     return mask;
  211. }
  212. //-------------------------------------
  213.  
  214. /*
  215. //-------------------------------------
  216. VOID Msg_GetWin()
  217. {
  218.     struct Window *Win;
  219.     register struct WinBlk *MsgBlk;
  220.     struct IntuiMessage *Msg;
  221.     struct WinMsg GadMsg;
  222.  
  223.     while (Msg=(struct IntuiMessage*)GetMsg(Port_Win))
  224.     {
  225.         Win=Msg->IDCMPWindow;
  226.         MsgBlk=(Win) ? (APTR)Win->UserData : 0;
  227.         GadMsg.Win=Win;
  228.         GadMsg.Blk=MsgBlk;
  229.         GadMsg.Gad=(APTR)Msg->IAddress;
  230.         GadMsg.Class=Msg->Class;
  231.         GadMsg.Code=Msg->Code;
  232.         GadMsg.Qualifier=Msg->Qualifier;
  233.         GadMsg.MouseX=Msg->MouseX;
  234.         GadMsg.MouseY=Msg->MouseY;
  235.         GadMsg.Sec=Msg->Seconds;
  236.         GadMsg.Mic=Msg->Micros;
  237.  
  238.         if (Msg->Class!=IDCMP_SIZEVERIFY) ReplyMsg((struct Message*)Msg);
  239.  
  240.         if (MsgBlk && Win)
  241.         {
  242.             switch (GadMsg.Class)
  243.             {
  244.                 case IDCMP_NEWPREFS:
  245.                     Window_Dispatcher(MsgBlk,Mode_Prefs);
  246.                     break;
  247.                 case INTUITICKS:
  248. //                    if (Blk_Help->WinPtr) Command_Help(&GadMsg);
  249.                     Window_Dispatcher(MsgBlk,Mode_Ticks);
  250.                     break;
  251.                 case IDCMP_CHANGEWINDOW:
  252.                     Window_StoreSize(MsgBlk);
  253.                     break;
  254.                 case IDCMP_RAWKEY:
  255.                     if (MsgBlk->KeyCheck) (MsgBlk->KeyCheck)(&GadMsg);
  256.                     break;
  257.                 case IDCMP_SIZEVERIFY:
  258.                     Window_ChangeSizeVerify(MsgBlk);
  259.                     ReplyMsg((struct Message*)Msg);
  260.                     break;
  261.                 case IDCMP_NEWSIZE:
  262.                     Window_ChangeSize(MsgBlk);
  263.                     break;
  264.                 case IDCMP_MENUPICK:
  265.                     Command_Menu(MsgBlk,GadMsg.Code);
  266.                     break;
  267.                 case IDCMP_CLOSEWINDOW:
  268.                     Window_Close(MsgBlk);
  269.                     break;
  270.                 case IDCMP_GADGETDOWN:
  271.                 case IDCMP_GADGETUP:
  272.                 case IDCMP_MOUSEMOVE:
  273.                     GadMsg.GadID=GadMsg.Gad->GadgetID;
  274.                     Command_CmpID(GadMsg.Gad,&GadMsg);
  275.                     break;
  276.                 case IDCMP_INACTIVEWINDOW:
  277.                     Window_Dispatcher(MsgBlk,Mode_InAct);
  278.                     break;
  279.             }
  280.         }
  281.     }
  282. }
  283. //-------------------------------------
  284. */
  285.  
  286. //-------------------------------------
  287. VOID Msg_GetCx()
  288. {
  289.     CxMsg *Msg=0;
  290.     LONG ID;
  291.  
  292.     if (Port_Cx)
  293.     {
  294.         while ((Msg=(APTR)GetMsg(Port_Cx)))
  295.         {
  296.             ID=CxMsgID(Msg);
  297.             ReplyMsg((APTR)Msg);
  298.  
  299.             switch (ID)
  300.             {
  301.                 case CXCMD_KILL:
  302.                         Quit();
  303.                         break;
  304.                 case CXCMD_ENABLE:
  305.                         ActivateCxObj(Broker,TRUE);
  306.                         break;
  307.                 case CXCMD_DISABLE:
  308.                         ActivateCxObj(Broker,FALSE);
  309.                         break;
  310.                 case CXCMD_UNIQUE:
  311.                 case CXCMD_APPEAR:
  312. //                        if (Blk_ActWin->WinPtr) ActivateWindow(Blk_ActWin->WinPtr);
  313.                         if (Scrn.Scrn) ScreenToFront(Scrn.Scrn);
  314.                         break;
  315.                 case CXCMD_DISAPPEAR:
  316.                         break;
  317.             }
  318.         }
  319.     }
  320. }
  321. //-------------------------------------
  322. UBYTE IconFile[DLEN+2];
  323. //-------------------------------------
  324. VOID Msg_GetWb()
  325. {
  326.     struct AppMessage *Msg=0;
  327.     BPTR IconPath;
  328.     UBYTE *IconName;
  329.     struct MsgBlk *Blk;
  330.  
  331. //struct AppMessage
  332. //    UWORD am_Type;        /* message type */
  333. //    ULONG am_UserData;        /* application specific */
  334. //    ULONG am_ID;        /* application definable ID */
  335. //    LONG am_NumArgs;        /* # of elements in arglist */
  336. //    struct WBArg *am_ArgList;    /* the arguements themselves */
  337. //    WORD am_MouseX;        /* mouse x position of event */
  338. //    WORD am_MouseY;        /* mouse y position of event */
  339.  
  340.     if (Port_Wb)
  341.     {
  342.         while ((Msg=(APTR)GetMsg(Port_Wb)))
  343.         {
  344.             switch (Msg->am_Type)
  345.             {
  346.                 case AMTYPE_APPWINDOW:
  347.                     Blk=(APTR)Msg->am_UserData;
  348.                     IconPath=Msg->am_ArgList[0].wa_Lock;
  349.                     IconName=Msg->am_ArgList[0].wa_Name;
  350.                     if (IconPath && IconName)
  351.                         if (NameFromLock(IconPath,IconFile,DLEN))
  352.                         {
  353.                             AddPart(IconFile,IconName,DLEN);
  354. //                            ...
  355.                         }
  356.                     break;
  357.             }
  358.             ReplyMsg((APTR)Msg);
  359.         }
  360.     }
  361. }
  362. //-------------------------------------
  363.  
  364.  
  365. //-------------------------------------
  366. VOID Command_Menu(struct Menu *Menu,LONG Code)
  367. {
  368.     struct MenuItem *MenuHit;
  369.     struct tkNewMenu *Data;
  370.  
  371.     if (Menu)
  372.     {
  373.         while ((MenuHit=ItemAddress(Menu,Code)) && (Code!=MENUNULL))
  374.         {
  375.             Data=GTMENUITEM_USERDATA(MenuHit);
  376.             Code=MenuHit->NextSelect;
  377.             if (Data->Func) (*Data->Func)();
  378.         }
  379.     }
  380. }
  381. //-----------------------------------
  382.  
  383.  
  384.  
  385. //-------------------------------------
  386. struct MsgPort *MakeMsgPort()
  387. {
  388.     struct MsgPort *port;
  389.  
  390.     do    { port=CreateMsgPort();
  391.         } while((!port) && ASK_AGAIN==display_error(ERR_PORT,ASK_EXIT|ASK_AGAIN|ASK_CONT));
  392.  
  393.     return port;
  394. }
  395. //-------------------------------------
  396. VOID FreeMsgPort(struct MsgPort **Port)
  397. {
  398.     struct Message *Msg;
  399.  
  400.     if (Port && *Port)
  401.     {
  402.         while ((Msg=GetMsg(*Port)))
  403.         {
  404.             ReplyMsg(Msg);
  405.         }
  406.         DeleteMsgPort(*Port);
  407.         *Port=0;
  408.     }
  409. }
  410. //-------------------------------------
  411. VOID MsgPort_Init()
  412. {
  413.     Port_Win=MakeMsgPort();
  414.     Port_Wb=MakeMsgPort();
  415.     Port_Cx=MakeMsgPort();
  416. }
  417. //-------------------------------------
  418. VOID MsgPort_Free()
  419. {
  420.     FreeMsgPort(&Port_Cx);
  421.     FreeMsgPort(&Port_Wb);
  422.     FreeMsgPort(&Port_Win);
  423. }
  424. //-------------------------------------
  425.  
  426.